﻿using ONetworkTalk.Codecs;
using ONetworkTalk.Contract;
using ONetworkTalk.Core;
using ONetworkTalk.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace imClient
{
    class Program
    {
        static void Main(string[] args)

        {

            Console.WriteLine("启动");

            TaskAsync().Wait();

        }



        static async Task TaskAsync()
        {
            OClientEngine oClientEngine = new OClientEngine();

            CustomizeHandler customizeHandler = new CustomizeHandler();

            await oClientEngine.RunEngineAsync("127.0.0.1", 5001, customizeHandler);

            oClientEngine.Login("1", "1", "1");

            while (true)
            {
                string readLine = Console.ReadLine();

                if (readLine == "close")
                {

                    await oClientEngine.Close();

                }
                else
                {
                    try
                    {
                        ChatContent content = new ChatContent()
                        {

                            Content = readLine
                        };

                        MessagePacket message = MessageCreater.CreateAckMessage("1", 0, content);

                        byte[] bytes = oClientEngine.BasicOutter.Query(message);

                        Console.WriteLine($"消息发送成功{readLine}");

                    }
                    catch (Exception ex)
                    {

                        Console.WriteLine($"消息发送失败{readLine}" + ex.Message);

                    }

                }

            }
        }
    }
}
